/*
 * @Description:
 * @version:
 * @Author: 171
 * @Date: 2022-08-31 10:04:26
 * @LastEditors: 171
 * @LastEditTime: 2022-09-22 12:11:38
 */
import express, {
  Express,
  Request,
  Response,
  NextFunction,
} from "express";
import bodyParser from 'body-parser';

import otherRouter from "./otherApi"
import { userRouter, articleRouter, validateRouter } from "./myapi";

const app: Express = express(); // 声明一个服务器app


app.use(bodyParser.urlencoded({ extended: false })) // 引入body-parser，保证传入的参数能被解析
app.use(bodyParser.json())

app.all("*", (req: Request, res: Response, next: NextFunction) => {
  res.header("Access-control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, authorization, public-key-pins");
  res.header("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});


app.use("/otherapi", otherRouter);

app.use("/myapi/user", userRouter);

app.use("/myapi/article", articleRouter);

app.use("/myapi", validateRouter);


app.listen(5555, () => {
  console.log("server is listening on http://localhost:5555");
});
